package com.lyf.aop.spring.annotation;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @AUTHOR LYF
 * @DATE 2022/2/12
 * @VERSION 1.0
 * @DESC
 * 1.连接点：需要增强的对象
 * 2.切入点：需要增强的方法
 * 3.通知（五种类型）：增强方法
 * 4.切面：切入过程
 */
@Component
@Aspect
public class UserServiceProxy {
    @Pointcut(value = "execution(* com.lyf.aop.spring.annotation.UserService.add(..))")
    void userPointCut(){}
    @Pointcut(value = "@annotation(com.lyf.aop.spring.annotation.LogAnnotation)")
    void testPointCut(){}
    /**
     * 在此（增强方法）之前执行
     */
    @Before(value = "userPointCut()") //也可以用execution表达式
    void before(){
        System.out.println("before executing...");
    }
    /**
     * 之后
     */
    @After(value = "userPointCut()")
    void after(){
        System.out.println("after executing...");
    }
    @Around(value = "userPointCut()")
    void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("around before...");
        proceedingJoinPoint.proceed();
        System.out.println("around after...");
    }
}
